<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/1/17
 * Time: 8:57
 */

namespace Admin\Model;


use Base\Model\BaseModel;

class DailyiteminfoModel extends BaseModel
{
    protected $_validate = array(
        array('name', 'require', '名称必须填写'),
        array('name', '', '名称已存在', 0, 'unique', 3),
        array('name_en','/^[a-zA-Z]+$/','英文名称必须为英文！',2),
        array('short_name_en','/^[a-zA-Z]+$/', '缩略英文名称必须为英文！',2),
//        array('name','/^[a-zA-Z_\x{4e00}-\x{9fa5}]+$/u', '名称不符合规则！',3),
    );

    protected $_auto = array(
        array('createtime','mydate','1','callback'),
        array('lastEditTime','mydate','3','callback'),
        array('status','1')
    );

    protected function mydate(){
        return date("Y-m-d H:i:s");
    }
    protected $_link = array(
        'iteminfo'=>array(
            'mapping_type'=>self::BELONGS_TO,
            'class_name'=>'dimdailyiteminfo',
            'foreign_key' => 'dimensionid',
            'parent_key' => 'id',
        ),
            //疾病所属分类
            'type' => array(
                'mapping_type' => self::BELONGS_TO,
                'class_name'    => 'dailyitemtype',
                'foreign_key' => 'typeid',
                'parent_key' => 'id',
                'mapping_fields' => 'id,typename'
            )
    );
}